package com.fengxing.ams.pub.util;

import java.util.Arrays;

import org.apache.http.Header;

/**
 * An object that wraps http call reusult and headers.
 * @author Kewen.Zhu
 * Sep 7, 2012
 *
 */
public class TecHttpResponse {
	private static String SERVER_INFO_HEADER_NAME = "ServerInfo";
	private String result;
	private Header[] headers;
	public TecHttpResponse(String result, Header[] headers) {
		this.result = result;
		this.headers = headers;
	}	
	public String getResult() {
    	return result;
    }
	public void setResult(String result) {
    	this.result = result;
    }
	public Header[] getHeaders() {
    	return headers;
    }
	public void setHeaders(Header[] headers) {
    	this.headers = headers;
    }
	
	/**
	 * get target Server information
	 * contains ip, port, and something like that. 
	 */
	public String getServerInfo() {
		for (Header header : headers) {
	        if (header.getName().equals(SERVER_INFO_HEADER_NAME)
	                || header.getName().equals("Server")) { // Server:SWS-157.241.136.240-A
	        	return header.getValue();
	        }
        }
    	return "";
    }
	
	@Override
	public String toString() {
		return "TecHttpResponse [result=" + result + ", headers=" + Arrays.toString(headers) + "]";
	}
	
}
